﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SpaceGame
{
    public class Battlecruiser : PlayerSpaceShip
    {
        public Battlecruiser(Position topLeft)
            : base(topLeft, new char[,] {
                {']', '-', '-', 'C', '='},
                {'}', '#', 'C', ' ', ' '},
                {'}', '#', 'C', ' ', ' '},
                {']', '-', '-', 'C', '='}
            })
        {
            char[,] secondFrame =
            {
                {']', '-', 'C', '=', '='},
                {'}', 'O', 'C', ' ', ' '},
                {'}', 'O', 'C', ' ', ' '},
                {']', '-', 'C', '=', '='}
            };

            char[,] thirdFrame =
            {
                {']', '-', '-', 'C', '='},
                {'}', 'X', 'C', ' ', ' '},
                {'}', 'X', 'C', ' ', ' '},
                {']', '-', '-', 'C', '='}
            };
            this.AddFrame(secondFrame);
            this.AddFrame(thirdFrame);
        }


        public override void UpdatePosition()
        {
            if (left == true)
            {
                this.Direction = new Position(0, -1);
                left = false;
            }
            else if (right == true)
            {
                this.Direction = new Position(0, 1);
                right = false;
            }
            else if (top == true)
            {
                this.Direction = new Position(-1, 0);
                top = false;
            }
            else if (down == true)
            {
                this.Direction = new Position(1, 0);
                down = false;
            }

            RestrainMovement();
            this.Direction = new Position(0, 0);    // no acceleration
        }
        public override IEnumerable<GameObject> CreateObjects()
        {
            if (isShooting)
            {
                isShooting = false;
                int height = this.Image.GetLength(0);
                int width = this.Image.GetLength(1);

                return new List<GameObject>
                {
                    new Bullet(new Position(this.TopLeft.Row + height/2 - 2, this.TopLeft.Col + width/2 + 1),
                        new char[,] { { (char)164 } }, 1, new Position(0, 3)),
                    new Bullet(new Position(this.TopLeft.Row + height/2 + 1, this.TopLeft.Col + width/2 + 1),
                        new char[,] { {(char)164 } }, 1, new Position(0, 3))
                };
            }

            return base.CreateObjects();
        }
    }
}
